package com.qingrongby.shop.api.v1;

import com.qingrongby.shop.bo.PageBO;
import com.qingrongby.shop.model.Spu;
import com.qingrongby.shop.service.SpuService;
import com.qingrongby.shop.util.CommonUtil;
import com.qingrongby.shop.vo.PagingDozer;
import com.qingrongby.shop.vo.SpuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

/**
 * @CLASSNAME 商品获取
 * @DESCRIPTION TODO
 * @AUTHOR hzp
 * @DATE 2020/6/21
 * @VERSION 1.0
 **/

@RestController
@Slf4j
@Api(tags = "商品获取接口")
@RequestMapping("v1/spu")
public class SpuController {

    @Autowired
    private SpuService spuService;

    @GetMapping("/latest")
    @ApiOperation(value = "分页获取")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start",defaultValue = "0"),
            @ApiImplicitParam(name = "count",defaultValue = "10")
    })
    @ResponseBody
    public PagingDozer<Spu, SpuVO> getPageSpu(@RequestParam(defaultValue = "0") Integer start,
                                              @RequestParam(defaultValue = "10")  Integer count)  {
        PageBO pageBO= CommonUtil.covertToPageCount(start,count);
        PagingDozer<Spu, SpuVO> spuPage=spuService.getLatestPagingSpu(pageBO.getPage(),pageBO.getCount());

        return  spuPage;
    }

}
